<div id="Line-group-formats"></div>
<div class="header">
<p>
Next: [[cvs: Line formats#Line formats|Line formats]], Up: [[cvs: diff options#diff options|diff options]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>

----

<div id="Line-group-formats-1"></div>
===== Line group formats =====

Line group formats let you specify formats suitable for many
applications that allow if-then-else input, including programming
languages and text formatting languages.  A line group format specifies
the output format for a contiguous group of similar lines.

For example, the following command compares the TeX file &lsquo;<tt>myfile</tt>&rsquo;
with the original version from the repository,
and outputs a merged file in which old regions are
surrounded by &lsquo;<code>\begin<nowiki>{</nowiki>em<nowiki>}</nowiki></code>&rsquo;-&lsquo;<code>\end<nowiki>{</nowiki>em<nowiki>}</nowiki></code>&rsquo; lines, and new
regions are surrounded by &lsquo;<code>\begin<nowiki>{</nowiki>bf<nowiki>}</nowiki></code>&rsquo;-&lsquo;<code>\end<nowiki>{</nowiki>bf<nowiki>}</nowiki></code>&rsquo; lines.

<div class="example" style="margin-left: 3.2em">
 cvs diff \
    --old-group-format='\begin<nowiki>{</nowiki>em<nowiki>}</nowiki>
 %&lt;\end<nowiki>{</nowiki>em<nowiki>}</nowiki>
 ' \
    --new-group-format='\begin<nowiki>{</nowiki>bf<nowiki>}</nowiki>
 %&gt;\end<nowiki>{</nowiki>bf<nowiki>}</nowiki>
 ' \
    myfile
</div>

The following command is equivalent to the above example, but it is a
little more verbose, because it spells out the default line group formats.

<div class="example" style="margin-left: 3.2em">
 cvs diff \
    --old-group-format='\begin<nowiki>{</nowiki>em<nowiki>}</nowiki>
 %&lt;\end<nowiki>{</nowiki>em<nowiki>}</nowiki>
 ' \
    --new-group-format='\begin<nowiki>{</nowiki>bf<nowiki>}</nowiki>
 %&gt;\end<nowiki>{</nowiki>bf<nowiki>}</nowiki>
 ' \
    --unchanged-group-format='%=' \
    --changed-group-format='\begin<nowiki>{</nowiki>em<nowiki>}</nowiki>
 %&lt;\end<nowiki>{</nowiki>em<nowiki>}</nowiki>
 \begin<nowiki>{</nowiki>bf<nowiki>}</nowiki>
 %&gt;\end<nowiki>{</nowiki>bf<nowiki>}</nowiki>
 ' \
    myfile
</div>

Here is a more advanced example, which outputs a diff listing with
headers containing line numbers in a &ldquo;plain English&rdquo; style.

<div class="example" style="margin-left: 3.2em">
 cvs diff \
    --unchanged-group-format=<nowiki>''</nowiki> \
    --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
 %&lt;' \
    --new-group-format='-------- %dN line%(N=1?:s) added after %de:
 %&gt;' \
    --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
 %&lt;-------- to:
 %&gt;' \
    myfile
</div>

To specify a line group format, use one of the options
listed below.  You can specify up to four line group formats, one for
each kind of line group.  You should quote <var>format</var>, because it
typically contains shell metacharacters.

;&lsquo;<code>--old-group-format=<var>format</var></code>&rsquo;
: These line groups are hunks containing only lines from the first file. The default old group format is the same as the changed group format if it is specified; otherwise it is a format that outputs the line group as-is.

;&lsquo;<code>--new-group-format=<var>format</var></code>&rsquo;
: These line groups are hunks containing only lines from the second file.  The default new group format is same as the changed group format if it is specified; otherwise it is a format that outputs the line group as-is.

;&lsquo;<code>--changed-group-format=<var>format</var></code>&rsquo;
: These line groups are hunks containing lines from both files.  The default changed group format is the concatenation of the old and new group formats.

;&lsquo;<code>--unchanged-group-format=<var>format</var></code>&rsquo;
: These line groups contain lines common to both files.  The default unchanged group format is a format that outputs the line group as-is.

In a line group format, ordinary characters represent themselves;
conversion specifications start with &lsquo;<code>%</code>&rsquo; and have one of the
following forms.

;&lsquo;<code>%&lt;</code>&rsquo;
: stands for the lines from the first file, including the trailing newline. Each line is formatted according to the old line format (see [[cvs: Line formats#Line formats|Line formats]]).

;&lsquo;<code>%&gt;</code>&rsquo;
: stands for the lines from the second file, including the trailing newline. Each line is formatted according to the new line format.

;&lsquo;<code>%=</code>&rsquo;
: stands for the lines common to both files, including the trailing newline. Each line is formatted according to the unchanged line format.

;&lsquo;<code>%%</code>&rsquo;
: stands for &lsquo;<code>%</code>&rsquo;.

;&lsquo;<code>%c'<var>C</var>'</code>&rsquo;
: where <var>C</var> is a single character, stands for <var>C</var>. <var>C</var> may not be a backslash or an apostrophe. For example, &lsquo;<code>%c':'</code>&rsquo; stands for a colon, even inside the then-part of an if-then-else format, which a colon would normally terminate.

;&lsquo;<code>%c'\<var>O</var>'</code>&rsquo;
: where <var>O</var> is a string of 1, 2, or 3 octal digits, stands for the character with octal code <var>O</var>. For example, &lsquo;<code>%c'\0'</code>&rsquo; stands for a null character.

;&lsquo;<code><var>F</var><var>n</var></code>&rsquo;
: where <var>F</var> is a <code>printf</code> conversion specification and <var>n</var> is one of the following letters, stands for <var>n</var>&rsquo;s value formatted with <var>F</var>.

:;&lsquo;<code>e</code>&rsquo;
:: The line number of the line just before the group in the old file.

:;&lsquo;<code>f</code>&rsquo;
:: The line number of the first line in the group in the old file; equals <var>e</var> + 1.

:;&lsquo;<code>l</code>&rsquo;
:: The line number of the last line in the group in the old file.

:;&lsquo;<code>m</code>&rsquo;
:: The line number of the line just after the group in the old file; equals <var>l</var> + 1.

:;&lsquo;<code>n</code>&rsquo;
:: The number of lines in the group in the old file; equals <var>l</var> - <var>f</var> + 1.

:;&lsquo;<code>E, F, L, M, N</code>&rsquo;
:: Likewise, for lines in the new file.


: The <code>printf</code> conversion specification can be &lsquo;<code>%d</code>&rsquo;, &lsquo;<code>%o</code>&rsquo;, &lsquo;<code>%x</code>&rsquo;, or &lsquo;<code>%X</code>&rsquo;, specifying decimal, octal, lower case hexadecimal, or upper case hexadecimal output respectively.  After the &lsquo;<code>%</code>&rsquo; the following options can appear in sequence: a &lsquo;<code>-</code>&rsquo; specifying left-justification; an integer specifying the minimum field width; and a period followed by an optional integer specifying the minimum number of digits. For example, &lsquo;<code>%5dN</code>&rsquo; prints the number of new lines in the group in a field of width 5 characters, using the <code>printf</code> format <code>&quot;%5d&quot;</code>.

;&lsquo;<code>(<var>A</var>=<var>B</var>?<var>T</var>:<var>E</var>)</code>&rsquo;
: If <var>A</var> equals <var>B</var> then <var>T</var> else <var>E</var>. <var>A</var> and <var>B</var> are each either a decimal constant or a single letter interpreted as above. This format spec is equivalent to <var>T</var> if <var>A</var>&rsquo;s value equals <var>B</var>&rsquo;s; otherwise it is equivalent to <var>E</var>.

: For example, &lsquo;<code>%(N=0?no:%dN) line%(N=1?:s)</code>&rsquo; is equivalent to &lsquo;<code>no lines</code>&rsquo; if <var>N</var> (the number of lines in the group in the new file) is 0, to &lsquo;<code>1 line</code>&rsquo; if <var>N</var> is 1, and to &lsquo;<code>%dN lines</code>&rsquo; otherwise.


----

<div class="header">
<p>
Next: [[cvs: Line formats#Line formats|Line formats]], Up: [[cvs: diff options#diff options|diff options]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>
This document was generated on <i>a sunny day</i> using [http://www.nongnu.org/texi2html/ <i>texi2html</i>].
